home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / ZIP_1_0.lha / src / screen.c < prev    next >
C/C++ Source or Header  |  1992-10-13  |  10KB  |  476 lines

  1. /*
  2.  * screen.c
  3.  *
  4.  * Generic screen manipulation routines. Most of these routines call the machine
  5.  * specific routines to do the actual work.
  6.  *
  7.  */
  8.  
  9. #include "ztypes.h"
  10.  
  11. /*
  12.  * select_window
  13.  *
  14.  * Put the cursor in the text or status window. The cursor is free to move in
  15.  * the status window, but is fixed to the input line in the text window.
  16.  *
  17.  */
  18.  
  19. #ifdef __STDC__
  20. void select_window (zword_t w)
  21. #else
  22. void select_window (w)
  23. zword_t w;
  24. #endif
  25. {
  26.  
  27.     window = w;
  28.     if (w == STATUS_WINDOW) {
  29.  
  30.         /* Status window: disable scripting, select the status window and
  31.            home the cursor */
  32.  
  33.         scripting_disable = ON;
  34.         select_status_window ();
  35.         if (h_type == V3 && status_size > 1)
  36.             move_cursor (2, 1);
  37.     } else {
  38.  
  39.         /* Text window: enable scripting and select text window */
  40.  
  41.         scripting_disable = OFF;
  42.         select_text_window ();
  43.     }
  44.  
  45.     /* Force text attribute to normal rendition */
  46.  
  47.     set_attribute (NORMAL);
  48.  
  49. }/* select_window */
  50.  
  51. /*
  52.  * set_status_size
  53.  *
  54.  * Set the size of the status window. The default size for the status window is
  55.  * zero lines for both type 3 and 4 games. The status line is handled specially
  56.  * for type 3 games and always occurs the line immediately above the status
  57.  * window.
  58.  *
  59.  */
  60.  
  61. #ifdef __STDC__
  62. void set_status_size (zword_t lines)
  63. #else
  64. void set_status_size (lines)
  65. zword_t lines;
  66. #endif
  67. {
  68.     int i;
  69.  
  70.     /* Maximum status window size is 255 */
  71.  
  72.     lines &= 0xff;
  73.     if (lines) {
  74.  
  75.         /* If size is non zero the turn on the status window */
  76.  
  77.         status_active = ON;
  78.  
  79.         /* Bound the status size to one line less than the total screen height */
  80.  
  81.         if (lines > (zword_t) (screen_rows - 1))
  82.             status_size = (zword_t) (screen_rows - 1);
  83.         else
  84.             status_size = lines;
  85.  
  86.         /* Create the status window, or resize it */
  87.  
  88.         create_status_window ();
  89.  
  90.         /* Need to clear the status window for type 3 games */
  91.  
  92.         if (h_type == V3 && lines >= 2) {
  93.             status_size++;
  94.             select_status_window ();
  95.             for (i = status_size; i > 1; i--) {
  96.                 move_cursor (i, 1);
  97.                 clear_line ();
  98.             }
  99.             select_text_window ();
  100.         }
  101.     } else {
  102.  
  103.         /* Lines are zero so turn off the status window */
  104.  
  105.         status_active = OFF;
  106.  
  107.         /* Reset the lines written counter */
  108.  
  109.         lines_written = 0;
  110.  
  111.         /* Always leave room for the status line if a type 3 game */
  112.  
  113.         if (h_type == V3)
  114.             status_size = 1;
  115.         else {
  116.             status_size = 0;
  117.  
  118.             /* Delete the status window */
  119.  
  120.             delete_status_window ();
  121.         }
  122.  
  123.         /* Return cursor to text window */
  124.  
  125.         select_text_window ();
  126.     }
  127.  
  128. }/* set_status_size */
  129.  
  130. /*
  131.  * erase_window
  132.  *
  133.  * Clear one or all windows on the screen.
  134.  *
  135.  */
  136.  
  137. #ifdef __STDC__
  138. void erase_window (zword_t w)
  139. #else
  140. void erase_window (w)
  141. zword_t w;
  142. #endif
  143. {
  144.  
  145.     if ((zbyte_t) w == (zbyte_t) RESET) {
  146.         set_status_size (0);
  147.         restart_screen ();
  148.     } else if ((zbyte_t) w == TEXT_WINDOW)
  149.         clear_text_window ();
  150.     else if ((zbyte_t) w == STATUS_WINDOW)
  151.         clear_status_window ();
  152.     else
  153.         return;
  154.  
  155. }/* erase_window */
  156.  
  157. /*
  158.  * erase_line
  159.  *
  160.  * Clear one line on the screen.
  161.  *
  162.  */
  163.  
  164. #ifdef __STDC__
  165. void erase_line (zword_t flag)
  166. #else
  167. void erase_line (flag)
  168. zword_t flag;
  169. #endif
  170. {
  171.  
  172.     if (flag == TRUE)
  173.         clear_line ();
  174.  
  175. }/* erase_line */
  176.  
  177. /*
  178.  * set_cursor_position
  179.  *
  180.  * Set the cursor position in the status window only.
  181.  *
  182.  */
  183.  
  184. #ifdef __STDC__
  185. void set_cursor_position (zword_t row, zword_t column)
  186. #else
  187. void set_cursor_position (row, column)
  188. zword_t row;
  189. zword_t column;
  190. #endif
  191. {
  192.  
  193.     /* Can only move cursor if format mode is off and in status window */
  194.  
  195.     if (format_mode == OFF && window == STATUS_WINDOW)
  196.         move_cursor (row, column);
  197.  
  198. }/* set_cursor_position */
  199.  
  200. /*
  201.  * pad_line
  202.  *
  203.  * Pad the status line with spaces up to a column position.
  204.  *
  205.  */
  206.  
  207. #ifdef __STDC__
  208. static void pad_line (int column)
  209. #else
  210. static void pad_line (column)
  211. int column;
  212. #endif
  213. {
  214.     int i;
  215.  
  216.     for (i = status_pos; i < column; i++)
  217.         write_char (' ');
  218.     status_pos = column;
  219.  
  220. }/* pad_line */
  221.  
  222. /*
  223.  * display_status_line
  224.  *
  225.  * Format and output the status line for type 3 games only.
  226.  *
  227.  */
  228.  
  229. #ifdef __STDC__
  230. void display_status_line (void)
  231. #else
  232. void display_status_line ()
  233. #endif
  234. {
  235.     int i, count = 0, end_of_string[3];
  236.     char *status_part[3];
  237.  
  238.     /* Redirect output to the status line buffer */
  239.  
  240.     set_print_modes (3, 0);
  241.  
  242.     /* Print the object description for global variable 16 */
  243.  
  244.     pad_line (1);
  245.     status_part[count] = &status_line[status_pos];
  246.     print_object (load_variable (16));
  247.     end_of_string[count++] = status_pos;
  248.     status_line[status_pos++] = '\0';
  249.  
  250.     if (get_byte (H_CONFIG) & CONFIG_TIME) {
  251.  
  252.         /* If a time display print the hours and minutes from global
  253.            variables 17 and 18 */
  254.  
  255.         pad_line (screen_cols - 21);
  256.         status_part[count] = &status_line[status_pos];
  257.         write_string (" Time: ");
  258.         print_time (load_variable (17), load_variable (18));
  259.         end_of_string[count++] = status_pos;
  260.         status_line[status_pos++] = '\0';
  261.     } else {
  262.  
  263.         /* If a moves/score display print the score and moves from global
  264.            variables 17 and 18 */
  265.  
  266.         pad_line (screen_cols - 31);
  267.         status_part[count] = &status_line[status_pos];
  268.         write_string (" Score: ");
  269.         print_number (load_variable (17));
  270.         end_of_string[count++] = status_pos;
  271.         status_line[status_pos++] = '\0';
  272.  
  273.         pad_line (screen_cols - 15);
  274.         status_part[count] = &status_line[status_pos];
  275.         write_string (" Moves: ");
  276.         print_number (load_variable (18));
  277.         end_of_string[count++] = status_pos;
  278.         status_line[status_pos++] = '\0';
  279.     }
  280.  
  281.     /* Pad the end of status line with spaces then disable output redirection */
  282.  
  283.     pad_line (screen_cols);
  284.     set_print_modes ((zword_t) -3, 0);
  285.  
  286.     /* Move the cursor to the top line of the status window, set the reverse
  287.        rendition and print the status line */
  288.  
  289.     select_window (STATUS_WINDOW);
  290.     move_cursor (1, 1);
  291.     set_attribute (REVERSE);
  292.  
  293.     /* Try and print the status line for a proportional font screen. If this
  294.        fails then remove embedded nulls in status line buffer and just output
  295.        it to the screen */
  296.  
  297.     if (print_status (count, status_part) == FALSE) {
  298.         for (i = 0; i < count; i++)
  299.             status_line[end_of_string[i]] = ' ';
  300.         status_line[status_pos] = '\0';
  301.         output_string (status_line);
  302.     }
  303.  
  304.     set_attribute (NORMAL);
  305.     select_window (TEXT_WINDOW);
  306.  
  307. }/* display_status_line */
  308.  
  309. /*
  310.  * blank_status_line
  311.  *
  312.  * Output a blank status line for type 3 games only.
  313.  *
  314.  */
  315.  
  316. #ifdef __STDC__
  317. void blank_status_line (void)
  318. #else
  319. void blank_status_line ()
  320. #endif
  321. {
  322.  
  323.     /* Redirect output to the status line buffer and pad the status line with
  324.        spaces then disable output redirection */
  325.  
  326.     set_print_modes (3, 0);
  327.     pad_line (screen_cols);
  328.     status_line[status_pos] = '\0';
  329.     set_print_modes ((zword_t) -3, 0);
  330.  
  331.     /* Move the cursor to the top line of the status window, set the reverse
  332.        rendition and print the status line */
  333.  
  334.     select_window (STATUS_WINDOW);
  335.     move_cursor (1, 1);
  336.     set_attribute (REVERSE);
  337.     output_string (status_line);
  338.     set_attribute (NORMAL);
  339.     select_window (TEXT_WINDOW);
  340.  
  341. }/* blank_status_line */
  342.  
  343. /*
  344.  * output_string
  345.  *
  346.  * Output a string of characters.
  347.  *
  348.  */
  349.  
  350. #ifdef __STDC__
  351. void output_string (const char *s)
  352. #else
  353. void output_string (s)
  354. const char *s;
  355. #endif
  356. {
  357.  
  358.     while (*s)
  359.         output_char (*s++);
  360.  
  361. }/* output_string */
  362.  
  363. /*
  364.  * output_string
  365.  *
  366.  * Output a string of characters followed by a new line.
  367.  *
  368.  */
  369.  
  370. #ifdef __STDC__
  371. void output_stringnl (const char *s)
  372. #else
  373. void output_stringnl (s)
  374. const char *s;
  375. #endif
  376. {
  377.  
  378.     while (*s)
  379.         output_char (*s++);
  380.     output_nl ();
  381.  
  382. }/* output_stringnl */
  383.  
  384. /*
  385.  * output_char
  386.  *
  387.  * Output a character and rendition selection. This routine also handles
  388.  * selecting rendition attributes such as bolding and reverse. There are
  389.  * five attributes distinguished by ascii codes 0 to 4. The attributes are:
  390.  * all attributes off (normal), reverse, bold, blink and underline.
  391.  *
  392.  */
  393.  
  394. #ifdef __STDC__
  395. void output_char (char c)
  396. #else
  397. void output_char (c)
  398. char c;
  399. #endif
  400. {
  401.  
  402.     /* Script character if scripting is enabled */
  403.  
  404.     if (scripting_disable == OFF)
  405.         script_char (c);
  406.  
  407.     /* If output is enabled then either select the rendition attribute
  408.        or just display the character */
  409.  
  410.     if (output_enable == ON)
  411.         if (c >= 1 && c <= 5)
  412.             set_attribute (--c);
  413.         else
  414.             display_char (c);
  415.  
  416. }/* output_char */
  417.  
  418. /*
  419.  * output_nl
  420.  *
  421.  * Scroll the text window up one line and pause the window if it is full.
  422.  *
  423.  */
  424.  
  425. #ifdef __STDC__
  426. void output_nl (void)
  427. #else
  428. void output_nl ()
  429. #endif
  430. {
  431.     int saved_scripting_disable;
  432.  
  433.     /* If scripting is enabled then print a new line */
  434.  
  435.     if (scripting_disable == OFF)
  436.         script_nl ();
  437.  
  438.     /* Don't print if output is disabled */
  439.  
  440.     if (output_enable == ON) {
  441.         if (window == TEXT_WINDOW) {
  442.  
  443.             /* If this is the text line then scroll it up one line */
  444.  
  445.             scroll_line ();
  446.  
  447.             /* See if we have filled the screen */
  448.  
  449.             if (++lines_written >= ((screen_rows - TOP_MARGIN) - status_size)) {
  450.  
  451.                 /* Display the new status line while the screen in paused */
  452.  
  453.                 if (h_type == V3)
  454.                     display_status_line ();
  455.  
  456.                 /* Reset the line count and display the more message */
  457.  
  458.                 lines_written = 0;
  459.                 saved_scripting_disable = scripting_disable;
  460.                 scripting_disable = ON;
  461.                 save_cursor_position ();
  462.                 output_string ("[MORE]");
  463.                 (void) input_character ();
  464.                 restore_cursor_position ();
  465.                 clear_line ();
  466.                 scripting_disable = saved_scripting_disable;
  467.             }
  468.         } else
  469.  
  470.             /* If this is the status window then just output a new line */
  471.  
  472.             output_string ("\n");
  473.     }
  474.  
  475. }/* output_nl */
  476.